package com.woniu.atms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.atms.entity.G5Car;
import com.woniu.atms.mapper.CarDao;
import com.woniu.atms.mapper.CarSeatDao;
import com.woniu.atms.service.CarSeatService;
import com.woniu.atms.service.CarService;
import com.woniu.atms.vo.pre.ticket.PreUserTicketVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 张奇
 * @title: CarServiceImpl
 * @projectName g5_atms
 * @description:
 * @date 2022/1/18 16:05
 */
@Service
public class CarServiceImpl implements CarService {
    @Resource
    private CarDao carDao;

    @Resource
    private CarSeatService carSeatService;

    @Override
    public G5Car queryById(Integer id) {
        return carDao.queryById(id);
    }

    @Override
    public PageInfo<G5Car> queryAll(Integer pageNum,Integer pageSize) {
        //设置pageHelper属性
        PageHelper.startPage(pageNum,pageSize);
        List<G5Car> list=carDao.queryAll();
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<G5Car> queryToCar(G5Car car,Integer pageNum,Integer pageSize) {
        //设置pageHelper属性
        PageHelper.startPage(pageNum,pageSize);
        List<G5Car> list=carDao.queryToCar(car);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<G5Car> queryByType(Integer typeId,Integer pageNum,Integer pageSize) {
        //设置pageHelper属性
        PageHelper.startPage(pageNum,pageSize);
        List<G5Car> list=carDao.queryByType(typeId);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<G5Car> queryByStatus(String status,Integer pageNum,Integer pageSize) {
        //设置pageHelper属性
        PageHelper.startPage(pageNum,pageSize);
        List<G5Car> list=carDao.queryByStatus(status);
        return new PageInfo<>(list);
    }

    @Override
    @Transactional
    public boolean insert(G5Car g5Car) {
        boolean flag=carDao.insert(g5Car);
        //添加座位
        carSeatService.addListByCarId(g5Car.getId());
        return  flag;
    }

    @Override
    public boolean update(G5Car g5Car) {
        return carDao.update(g5Car);
    }

    @Override
    public boolean deleteById(Integer id) {
        return carDao.deleteById(id);
    }
}
